﻿package mortal.game.view.copy.guildCopy
{
    import Message.DB.Tables.*;
    import com.gengine.global.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.map3D.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.guildCopy.renderer.*;
    import mortal.mvc.core.*;

    public class GuildCopyHurtListPanel extends View
    {
        private var _bodySprite:Sprite;
        private var _bgSprite:Sprite;
        private var _bgImg:GBitmap;
        private var _moveBtn:GLoadedButton;
        private var _btnShowTrack:GuildCopyHurtListShowAndHide;
        private var _hurtList:GTileList;
        private var _leftTime:SecTimerView;
        private var _rewardDesc:GTextFiled;
        private var _txtContribute:GTextFiled;
        private var _txtResource:GTextFiled;
        private var _itemList:GTileList;
        private var _dragRect:Rectangle;
        private var _uiInitOver:Boolean = false;

        public function GuildCopyHurtListPanel()
        {
            this._dragRect = new Rectangle();
            this.layer = LayerManager.uiLayer;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            mouseEnabled = false;
            this._bodySprite = new Sprite();
            addChild(this._bodySprite);
            this._bodySprite.mouseEnabled = false;
            this._bgSprite = new Sprite();
            this._bodySprite.addChild(this._bgSprite);
            this._bgSprite.mouseEnabled = false;
            this._bgSprite.mouseChildren = false;
            this._bgImg = UIFactory.bitmap("TaskTrackBg", 0, 1, this._bgSprite);
            this._bgImg.width = 238;
            var _loc_1:* = GlobalStyle.textFormatAnjin;
            _loc_1.align = TextFormatAlign.CENTER;
            pushUIToDisposeVec(UIFactory.textField(Language.getString(70933), 20, 0, 198, 20, this._bodySprite, _loc_1));
            this._moveBtn = UIFactory.gLoadedButton(ImagesConst.TaskTrackMove_upSkin, 0, 3, 18, 18, this._bodySprite);
            this._moveBtn.toolTipData = HTMLUtil.addColor(Language.getString(20143), "#FFFFFF");
            this._btnShowTrack = new GuildCopyHurtListShowAndHide();
            this._btnShowTrack.width = 18;
            this._btnShowTrack.height = 18;
            this._btnShowTrack.x = 218;
            this._btnShowTrack.y = 3;
            this.addChild(this._btnShowTrack);
            this._btnShowTrack.configEventListener(MouseEvent.CLICK, this.onClickHide);
            var _loc_2:* = GlobalStyle.textFormatPutong;
            _loc_2.align = "center";
            pushUIToDisposeVec(UIFactory.bg(0, 22, 238, 22, this._bodySprite, ImagesConst.RegionTitleBg));
            pushUIToDisposeVec(UIFactory.textField("" + Language.getString(70934), 5, 22, 30, 22, this._bodySprite, _loc_2));
            pushUIToDisposeVec(UIFactory.textField("" + Language.getString(70935), 30, 22, 103, 22, this._bodySprite, _loc_2));
            pushUIToDisposeVec(UIFactory.textField("" + Language.getString(70936), 120, 22, 118, 22, this._bodySprite, _loc_2));
            this._hurtList = UIFactory.tileList(0, 46, 238, 210, this._bodySprite);
            this._hurtList.rowHeight = 19;
            this._hurtList.columnWidth = 238;
            this._hurtList.setStyle("cellRenderer", GuildCopyHurtListCellRenderer);
            pushUIToDisposeVec(UIFactory.bg(0, 257, 238, 22, this._bodySprite, ImagesConst.RegionTitleBg));
            var _loc_3:* = GlobalStyle.textFormatLv;
            _loc_3.align = "center";
            this._leftTime = UIFactory.secTimeView("" + Language.getString(70937), 0, 257, 238, 22, this._bodySprite, GlobalStyle.textFormatLv.center());
            this._leftTime.timeOutHandler = this.timeCompl;
            this._rewardDesc = UIFactory.textField("" + Language.getString(70938), 15, 280, 223, 22, this._bodySprite);
            this._txtContribute = UIFactory.textField("" + Language.getString(70939), 15, 302, 223, 22, this._bodySprite);
            this._txtResource = UIFactory.textField("" + Language.getString(70940), 122, 302, 223, 22, this._bodySprite);
            pushUIToDisposeVec(UIFactory.bg(0, 328, 238, 76, this._bodySprite, ImagesConst.RegionTitleBg));
            this._itemList = UIFactory.tileList(0, 330, 238, 100, this._bodySprite);
            this._itemList.rowHeight = 50;
            this._itemList.columnWidth = 50;
            this._itemList.setStyle("cellRenderer", GuildCopyRewardItemListCellRenderer);
            this._moveBtn.configEventListener(MouseEvent.MOUSE_DOWN, this.onMoveBtnMouseHandler);
            this._uiInitOver = true;
            this.updateAll();
            return;
        }// end function

        private function onClickHide(event:MouseEvent) : void
        {
            this._bodySprite.visible = !this._bodySprite.visible;
            return;
        }// end function

        public function updateAll(param1:Object = null) : void
        {
            if (!this._uiInitOver)
            {
                return;
            }
            var _loc_2:* = Cache.instance.copy.guildCopy;
            if (_loc_2.copeyLeftTime > 0 && this._leftTime.secTimerViewData == null)
            {
                this._leftTime.setLeftTime(_loc_2.copeyLeftTime);
                this._leftTime.configEventListener(EventName.SecViewTimeChange, this.onSecChange);
            }
            this.updateHurtList();
            this.updateReward();
            return;
        }// end function

        private function onSecChange(event:DataEvent) : void
        {
            var _loc_2:* = Cache.instance.copy.guildCopy;
            if (this._leftTime.getLeftTime() <= 60 * 3 && (this._leftTime.colorChange == null || this._leftTime.colorChange.length == 0))
            {
                this._leftTime.colorChange = [GlobalStyle.colorHong, GlobalStyle.colorLv];
            }
            else if (this._leftTime.getLeftTime() > 60 * 3 && this._leftTime.colorChange && this._leftTime.colorChange.length > 0)
            {
                this._leftTime.colorChange = null;
            }
            return;
        }// end function

        public function updateHurtList() : void
        {
            if (Cache.instance.copy.guildCopy.hurtInfo == null)
            {
                return;
            }
            var _loc_1:* = Cache.instance.copy.guildCopy.hurtInfo.topInfos.concat();
            var _loc_2:int = 0;
            while (_loc_2 < 10)
            {
                
                if (_loc_2 >= _loc_1.length)
                {
                    _loc_1.push(new Object());
                }
                _loc_2++;
            }
            this._hurtList.dataProvider = new DataProvider(_loc_1);
            this._hurtList.selectedIndex = 10;
            this._hurtList.drawNow();
            return;
        }// end function

        public function updateReward() : void
        {
            var _loc_1:* = Cache.instance.copy.guildCopy;
            if (_loc_1.rewardInfo == null)
            {
                return;
            }
            if (_loc_1.rewardInfo.color == 0)
            {
                _loc_1.rewardInfo.color = 1;
            }
            var _loc_2:* = GuildBossCopyConfig.instance.getConfigByColor(_loc_1.rewardInfo.color);
            var _loc_3:* = "(" + Language.getStringByParam(70942, GameDefConfig.instance.getGuildBossColorName(_loc_2.color), _loc_2.color);
            this._rewardDesc.htmlText = HTMLUtil.addColor("" + Language.getString(70941), GlobalStyle.colorHuang) + HTMLUtil.addColor(_loc_3, GlobalStyle.colorLan);
            this._txtContribute.htmlText = HTMLUtil.addColor("" + Language.getString(70943), GlobalStyle.colorPutong) + HTMLUtil.addColor(_loc_1.rewardInfo.contribution.toString() + "X" + _loc_2.color.toString(), GlobalStyle.colorHuang);
            this._txtResource.htmlText = HTMLUtil.addColor("" + Language.getString(70944), GlobalStyle.colorPutong) + HTMLUtil.addColor(_loc_1.rewardInfo.resource.toString() + "X" + _loc_2.color.toString(), GlobalStyle.colorHuang);
            this._itemList.dataProvider = new DataProvider(_loc_1.rewardInfo.items);
            this._itemList.drawNow();
            return;
        }// end function

        override public function stageResize() : void
        {
            this.x = SceneRange.display.width - 240;
            this.y = 170;
            return;
        }// end function

        private function onMoveBtnMouseHandler(event:MouseEvent) : void
        {
            this._dragRect.x = 0;
            this._dragRect.y = 0;
            this._dragRect.width = SceneRange.display.width - 30;
            this._dragRect.height = SceneRange.display.height - 30;
            startDrag(false, this._dragRect);
            Global.stage.addEventListener(MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            return;
        }// end function

        private function onStageMouseUpHandler(event:MouseEvent) : void
        {
            stopDrag();
            Global.stage.removeEventListener(MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            return;
        }// end function

        private function timeCompl() : void
        {
            this._leftTime.stop();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            if (Global.stage.hasEventListener(MouseEvent.MOUSE_UP))
            {
                Global.stage.removeEventListener(MouseEvent.MOUSE_UP, this.onStageMouseUpHandler);
            }
            DisplayUtil.removeMe(this._bodySprite);
            DisplayUtil.removeMe(this._bgSprite);
            this._bodySprite = null;
            this._bgSprite = null;
            this._dragRect = null;
            this._uiInitOver = false;
            this._bgImg.dispose(param1);
            this._moveBtn.dispose(param1);
            this._btnShowTrack.dispose(param1);
            this._hurtList.dispose(param1);
            this._rewardDesc.dispose(param1);
            this._txtContribute.dispose(param1);
            this._txtResource.dispose(param1);
            this._itemList.dispose(param1);
            this._leftTime.dispose(param1);
            this._bgImg = null;
            this._moveBtn = null;
            this._btnShowTrack = null;
            this._hurtList = null;
            this._rewardDesc = null;
            this._txtContribute = null;
            this._txtResource = null;
            this._itemList = null;
            this._leftTime = null;
            return;
        }// end function

    }
}
